package cn.haoxsf.app.system.service.impl;

import cn.haoxsf.app.common.util.ToolUtil;
import cn.haoxsf.app.system.entity.Business;
import cn.haoxsf.app.system.mapper.BusinessMapper;
import cn.haoxsf.app.system.model.vo.BusinessResult;
import cn.haoxsf.app.system.service.IBusinessService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商户表 服务实现类
 * </p>
 *
 * @author Ele  qvbanfm@qq.com
 * @since 2020-03-11
 */
@Service
public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business> implements IBusinessService {

    /**
     * 查询商户
     *
     * @param memberId 用户id
     * @return BusinessResult
     */
    @Override
    public BusinessResult getOne(String memberId) {
        BusinessResult result = new BusinessResult();
        Business businessByMemberId = baseMapper.selectOne(new QueryWrapper<Business>().eq("user_id", memberId));
        if(ToolUtil.isEmpty(businessByMemberId)){
            return null;
        }
        BeanUtils.copyProperties(businessByMemberId,result);
        return result;
    }

    /**
     * 改变商户的开工状态
     *
     * @param userId    用户id
     * @param workState 要修改的状态
     */
    @Override
    public Boolean changeWorkState(Long userId, String workState) {
        this.baseMapper.changeWorkState(userId,workState);
        return true;
    }
}
